package com.zhou.project.configurations.swagger;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @project spring-boot-project
 * @author zhouhonggang
 * @datetime 2021/8/21 15:31
 * @version 1.0.0
 * @description: Swagger3自定配置
 */
@EnableOpenApi
@Configuration
public class Swagger3Config {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("\u5728\u7ebf\u63a5\u53e3\u6587\u6863")
                .description("\u54a8\u8be2\u670d\u52a1\u5f00\u53d1\u8005\u5468\u5b8f\u521a")
                .contact(new Contact("ZhouHongGang", "http://www.javakc.com", "honggang_z@163.com"))
                .version("1.2.0")
                .build();
    }

}
